package com.jamin.demo.hanzitopinyin;

import java.util.ArrayList;

import com.jamin.demo.R;
import com.jamin.demo.hanzitopinyin.HanziToPinyin.Token;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class HanziToPinyinTestActivity extends Activity {
	/** Called when the activity is first created. */

	private static final String TAG = "==========HanziToPinyinTestActivity";
	
	Button button = null;
	TextView tv = null;
	EditText et = null;
	HanziToPinyin hztpy = null;
	
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hanzitopinyin);

		hztpy = HanziToPinyin.getInstance();
		button = (Button) findViewById(R.id.button1);
		tv = (TextView) findViewById(R.id.textview);
		et = (EditText) findViewById(R.id.editText1);

		button.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				change();
			}


		});

	}

	private void change() {
		// TODO Auto-generated method stub
		String hanzi = et.getText().toString();
		
		ArrayList<Token> list = hztpy.get(hanzi);
		
		Log.d(TAG, "size = " + list.size());
		StringBuilder builder = new StringBuilder();
		for(int i = 0 ; i < list.size(); i++){
			
			Token token = list.get(i);
			String aaa = token.target;
			builder.append(aaa);
			if(token.type == HanziToPinyin.Token.PINYIN){
				builder.append(" ");
				builder.append(token.source);
				builder.append(" ");
			}else{
				builder.append(" ");
			}
			
		}
		
		tv.setText(builder);
		
		
		
	}














}